<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:jsf="http://xmlns.jcp.org/jsf">
    <h:head>
    </h:head>

    <h:body>
        <f:metadata>
            <f:viewParam name="guestbookId" value="#{guestbookResponsesPage.guestbookId}"/>
            <f:viewParam name="dataverseId" value="#{guestbookResponsesPage.dataverseId}"/>
            <f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
            <f:viewAction action="#{guestbookResponsesPage.init}"/> 
            <f:viewAction action="#{dataverseHeaderFragment.initBreadcrumbs(guestbookResponsesPage.dataverse)}"/> 
            <f:viewAction action="#{dataverseHeaderFragment.addBreadcrumb('/manage-guestbooks.xhtml?dataverseId='.concat(guestbookResponsesPage.dataverseId), bundle['dataset.manageGuestbooks.pageTitle'])}"/>   
            <f:viewAction action="#{dataverseHeaderFragment.addBreadcrumb(bundle['dataset.guestbookResponses.pageTitle'])}"/>
        </f:metadata>
        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{bundle['dataset.guestbookResponses.pageTitle']}"/>
            <ui:param name="dataverse" value="#{guestbookResponsesPage.dataverse}"/>
            <ui:param name="showMessagePanel" value="#{true}"/>
            <ui:define name="body">
                <h:form id="manageGuestbooksForm">
                    <p:fragment id="tooManyEntries" rendered="#{guestbookResponsesPage.guestbook.responseCount gt systemConfig.guestbookResponsesPageDisplayLimit}">
                        <div class="row">
                            <div class="col-xs-12">
                                <div id="no-clients-message" class="alert alert-warning" role="alert">
                                    <span class="glyphicon glyphicon-warning-sign"/>
                                    <h:outputFormat value=" #{bundle['dataset.guestbooksResponses.tooManyResponses.message']}" escape="false">
                                        <f:param value="#{systemConfig.guestbookResponsesPageDisplayLimit}"/>
                                        <f:param value="#{guestbookResponsesPage.guestbook.responseCount}"/>
                                    </h:outputFormat>
                                </div>
                            </div>
                        </div>
                    </p:fragment>
                    <div class="row">
                        <label for="guestbookNameStatic" class="col-sm-2 control-label">
                            <span>#{bundle['dataset.manageGuestbooks.tab.action.btn.view.dialog.datasetGuestbook']}</span>
                        </label>
                        <div class="col-sm-9">
                            #{guestbookResponsesPage.guestbook.name}
                        </div>
                    </div>
                    <div class="row" id="resultsCountPaginatorBlock">
                        <div class="col-xs-6">
                            <!-- number of results -->
                            <div class="results-count margin-top">
                                <h:outputFormat rendered="#{guestbookResponsesPage.guestbook.responseCount lt systemConfig.guestbookResponsesPageDisplayLimit}"
                                                styleClass="highlightBold" value="#{bundle['dataset.guestbooksResponses.count.responses']}">
                                    <f:param value="#{guestbookResponsesPage.guestbook.responseCount}"/>
                                </h:outputFormat>
                                <h:outputFormat rendered="#{guestbookResponsesPage.guestbook.responseCount gt systemConfig.guestbookResponsesPageDisplayLimit}"
                                                styleClass="highlightBold" value="#{bundle['dataset.guestbooksResponses.count.toofresults']}">
                                    <f:param value="#{guestbookResponsesPage.guestbook.responseCount - 5000}"/>
                                    <f:param value="#{guestbookResponsesPage.guestbook.responseCount}"/>
                                    <f:param value="#{guestbookResponsesPage.guestbook.responseCount}"/>
                                </h:outputFormat>
                            </div>
                        </div>
                        <div class="col-xs-6">
                            <p class="button-block text-right">
                                <button class="btn btn-default" jsf:id="downloadResponsesLink" jsf:action="#{guestbookResponsesPage.streamResponsesByDataverseAndGuestbook()}">
                                     <span class="glyphicon glyphicon-download-alt"/> #{bundle['dataset.manageGuestbooks.download.responses']}
                                </button>
                            </p>
                        </div>
                    </div>
                    <p:dataTable id="responsesGuestbook" value="#{guestbookResponsesPage.responsesAsArray}" var="response">
                        <p:column sortBy="#{response[0]}" headerText="#{bundle['dataset.guestbooksResponses.dataset']}">
                            <h:outputText value="#{response[0]}"/>
                        </p:column>
                        <p:column sortBy="#{response[1]}" headerText="#{bundle['dataset.guestbooksResponses.date']}">
                            #{response[1]}
                        </p:column>
                        <p:column sortBy="#{response[2]}" headerText="#{bundle['dataset.guestbooksResponses.type']}">
                            #{response[2]}
                        </p:column>
                        <p:column sortBy="#{response[3]}" headerText="#{bundle['dataset.guestbooksResponses.file']}">
                            #{response[3]}
                        </p:column>
                        <p:column sortBy="#{response[4]}" headerText="#{bundle['dataset.guestbooksResponses.user']}">
                            <h:outputText value="#{response[4]}"/>
                        </p:column>
                        <p:column headerText="#{bundle['dataset.guestbooksResponses.customQuestions']}" >
                            <ui:repeat value="#{response[5]}" var="customQResponse">
                            <b><h:outputText value="#{customQResponse[0]}"/>: </b>
                            <h:outputText escape="false" value="#{customQResponse[1]}"/>
                            <br />
                            </ui:repeat>
                        </p:column>
                    </p:dataTable>
                </h:form>
            </ui:define>
        </ui:composition>
    </h:body>
</html>

